/**
 * 
 */
package org.conan.groupapp.framework.dao.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.conan.groupapp.framework.dao.IBaseDao;
import org.conan.groupapp.framework.entity.ParamBean;

import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * @author Administrator
 *
 */
//@Component
public abstract class BaseDaoImpl<T extends ParamBean> implements IBaseDao<T> {
	protected String sqlMapNamespace;
	@Resource
	private SqlMapClient mainSqlMapClient;

	
	public void init(){
		
	}
	
	@Override
	public String insert(T t) throws Exception {
		return  (String)mainSqlMapClient.insert(sqlMapNamespace+"insert"+t);
	}

	@Override
	public int updateByPrimaryKey(T t) throws Exception {
		return mainSqlMapClient.update(sqlMapNamespace+"updateByPrimaryKey",t);
	}

	@Override
	public int deleteByPrimaryKey(Integer primaryKey) throws Exception {
		return mainSqlMapClient.delete(sqlMapNamespace+"deleteByPrimaryKey",primaryKey);
	}
	
	@Override
	public int deleteByCondition(T t) throws Exception {
		return mainSqlMapClient.delete(sqlMapNamespace+"deleteByCondition",t);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<T> selectByCondition(T t, int rowStart, int rowEnd)
			throws Exception {
		return (List<T>)mainSqlMapClient.queryForList(sqlMapNamespace+"selectByCondition", t, rowStart, rowEnd-rowStart);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Map> selectMapByCondition(T t,int rowStart, int rowEnd) throws Exception{
		return (List<Map>)mainSqlMapClient.queryForList(sqlMapNamespace+"selectMapByCondition", t, rowStart, rowEnd-rowStart);
	}

	@Override
	public int countByCondition(T t) throws Exception {
		return (Integer)mainSqlMapClient.queryForObject(sqlMapNamespace+"countByCondition",t);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public T selectByPrimaryKey(Integer primaryKey) throws Exception{
		return (T)mainSqlMapClient.queryForObject(sqlMapNamespace+"selectByPrimaryKey",primaryKey);
	}
	public SqlMapClient getMainSqlMapClient() {
		return mainSqlMapClient;
	}

	public void setMainSqlMapClient(SqlMapClient mainSqlMapClient) {
		this.mainSqlMapClient = mainSqlMapClient;
	}
	
}
